package org.vy.dal.dao.admin;

import java.util.ArrayList;
import java.util.List;

import org.vy.dal.QueryManager;

public class VyAdmEmpGroupDAO {
	private static final String FIND_BY_GROUP_CODE = "SELECT * FROM <TABLE> WHERE GROUP_CODE = m_groupCode";
	private static final String FIND_BY_VY_ID = "SELECT * FROM <TABLE> WHERE VY_ID = m_vyId";
	private static final String INSERT = "INSERT INTO <TABLE> (GROUP_CODE,VY_ID,LAST_UPDATED_BY,LAST_UPDATED_ON) VALUES(m_groupCode,m_vyId,m_lastUpdatedBy,m_lastUpdatedOn)";
	private static final String DELETE_BY_VY_ID = "DELETE FROM <TABLE> WHERE GROUP_CODE = m_groupCode";
	private static final String DELETE_BY_GROUP_CODE = "DELETE FROM <TABLE> WHERE VY_ID = m_vyId";
	private static final String DELETE_BY_GROUP_AND_VY_ID = "DELETE FROM <TABLE> WHERE GROUP_CODE = m_groupCode AND VY_ID = m_vyId";

	@SuppressWarnings("unchecked")
	public static List<VyAdmEmpGroupDO> findByGroupCode(String key) throws Exception {
		VyAdmEmpGroupDO dto = new VyAdmEmpGroupDO();
		List<VyAdmEmpGroupDO> lst = new ArrayList<VyAdmEmpGroupDO>();
		dto.setGroupCode(key);
		lst = (List<VyAdmEmpGroupDO>)QueryManager.executeListQuery(dto, FIND_BY_GROUP_CODE);
		return lst;
	}

	@SuppressWarnings("unchecked")
	public static List<VyAdmEmpGroupDO> findByVyId(String key) throws Exception {
		VyAdmEmpGroupDO dto = new VyAdmEmpGroupDO();
		List<VyAdmEmpGroupDO> lst = new ArrayList<VyAdmEmpGroupDO>();
		dto.setVyId(key);
		lst = (List<VyAdmEmpGroupDO>)QueryManager.executeListQuery(dto, FIND_BY_VY_ID);
		return lst;
	}

	public static VyAdmEmpGroupDO insert(VyAdmEmpGroupDO dto) throws Exception {

		dto = (VyAdmEmpGroupDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static boolean deleteByVyId(String key) throws Exception {
		VyAdmEmpGroupDO dto = new VyAdmEmpGroupDO();
		dto.setVyId(key);
		return QueryManager.executeDelete(dto, DELETE_BY_VY_ID);
	}

	public static boolean deleteByGroupCode(String key) throws Exception {
		VyAdmEmpGroupDO dto = new VyAdmEmpGroupDO();
		dto.setGroupCode(key);
		return QueryManager.executeDelete(dto, DELETE_BY_GROUP_CODE);
	}

	public static boolean deleteByGroupAndVyId(String group, String module) throws Exception {
		VyAdmEmpGroupDO dto = new VyAdmEmpGroupDO();
		dto.setGroupCode(group);
		dto.setVyId(module);
		return QueryManager.executeDelete(dto, DELETE_BY_GROUP_AND_VY_ID);
	}
}
